
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

const windowHeight=function(head){
  let clientWidth=wx.getSystemInfoSync().windowWidth;//rpx
  let clientHeight=wx.getSystemInfoSync().windowHeight;
  let r=clientWidth/750;
  let height=clientHeight/r;

  if(head!=null){
    return height-head;
  }else{
    return height;
  }
}

const msg=function(msg,callback){
  wx.showToast({
    title: msg,
    icon:'none',
    success:callback
  })
}

const navigateTo=function(url){
  wx.navigateTo({
    url: url
  })

}

let test=function(callback){
  console.log("callback:");
  callback();
}

let objToMap=function  objToMap(obj){
  let strMap = new Map();
  for (let k of Object.keys(obj)) {
    //console.log(k);
    strMap.set(JSON.parse(k),obj[k]);
  }
  return strMap;
}

module.exports = {
  formatTime,
  windowHeight,
  msg,
  navigateTo,
  objToMap,
  test
}

